#include "Core.h"

#include "Fly.h"
#include "FireFly.h"
#include "ShaderFactory.h"

#include "CommonHeaders.h"

#include <array>

Core::Core(void)
{
}


Core::~Core(void)
{
}

Core* Core::Instance()
{
	static Core* instance = nullptr;
	if( instance == nullptr )
		instance = new Core();

	return instance;
}

void Core::Render()
{
	glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	for (unsigned int i = 0; i < objects.size(); i++)
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(80.0,1,0.001,500.0);

		std::array<GLfloat, 16> projection;
		glGetFloatv(GL_PROJECTION_MATRIX, projection.data());
		glUniformMatrix4fv(glGetUniformLocation(objects[i]->GetProgram(), "gl_ProjectionMatrix"), 1, GL_FALSE, projection.data());
		//glUniform1f(glGetUniformLocation(objects[i]->GetProgram(), "scale"), 1);
		objects[i]->Render();
	}
		

	glutSwapBuffers();
}

void Core::Init()
{
	objects.push_back(new Fly(
		ShaderFactory::Instance()->getShader("DefaultVertexShader.glsl", GL_VERTEX_SHADER), 
		ShaderFactory::Instance()->getShader("DefaultFragmentShader.glsl", GL_FRAGMENT_SHADER)
		));
	objects.push_back(new FireFly(
		ShaderFactory::Instance()->getShader("FireFlyVS.glsl", GL_VERTEX_SHADER), 
		ShaderFactory::Instance()->getShader("FireFlyFS.glsl", GL_FRAGMENT_SHADER)
		));

	
}

void Core::Animate()
{

}
